require("datastream")
/*---------------------------------------------------------
 Gamemode functions
 ---------------------------------------------------------*/

function GM:Initialize()
	self.BaseClass:Initialize()
end

function GM:PlayerInitialSpawn( ply ) //"When the player first joins the server and spawns" function
	//ply:LoadMoney()
	//ply:LoadUnlocks()
	//ply:LoadOtherInfo()
end
   
function GM:PlayerSpawn( ply )  //After initial spawn, let's do some functions
    ply:SetWalkSpeed( 200 )  
	ply:SetRunSpeed( 325 )
	ply:SetTeam(TEAM_GDI)
end

function GM:PlayerLoadout( ply ) 

	/* Make sure they have gravity gun rights rights */
	if (ply:HasRight("gravitygun"))
		ply:Give("weapon_physcannon")
	end
	
	/* Make sure they have toolgun rights */
	if (ply:HasRight("toolgun"))
		ply:Give("gmod_tool")
	end
	
	/* Make sure they have phys gun rights */
	if (ply:HasRight("physgun"))
		ply:Give("weapon_physgun")
	end
	
	/* Make sure they have crowbar rights */
	if (ply:HasRight("crowbar"))
		ply:Give("weapon_crowbar")
	end
	
	/* Make sure they have crowbar rights */
	if (ply:HasRight("rpg"))
		ply:Give("weapon_rpg")
	end
	
	local Team = ply:Team() or 1
	
	for k,v in pairs(ExtraTeams[Team].Weapons) do
		ply:Give(v)
	end
	
	-- Switch to prefered weapon if they have it
	local cl_defaultweapon = ply:GetInfo( "cl_defaultweapon" )
	
	if ply:HasWeapon( cl_defaultweapon ) then
		ply:SelectWeapon( cl_defaultweapon )
	else
		ply:SelectWeapon( "weapon_physgun" )
	end
end

function GM:PlayerInitialize( pl )
    --Anything needed here
end

function GM:CanTool(ply, trace, mode)
	if not self.BaseClass:CanTool(ply, trace, mode) then return false end

	if ValidEntity(trace.Entity) then
		if trace.Entity.onlyremover then
			if mode == "remover" then
				/* Let prop protection decide this */
				return
			else
				/* Enforce this */
				return false
			end
		end

		if trace.Entity.nodupe and (mode == "weld" or
					mode == "weld_ez" or
					mode == "spawner" or
					mode == "duplicator" or
					mode == "adv_duplicator") then
			/* Enforce this */
			return false
		end
	end
	
	/* Let prop protection decide this */
	return
end